#include "ADC_HAL_KA.h"

void vfnADC_ResolutionSet8 (void)
{
    ADCCFG_MODE = 0;
}

void vfnADC_ResolutionSet10 (void)
{
    ADCCFG_MODE = 2;   
}

void vfnADC_LowPowerMode (void) 
{
    ADCCFG_ADLPC = 1;
}

void vfnADC_HighSpeedMode (void) 
{
    ADCCFG_ADLPC = 0;
}

void vfnADC_ClockDivideSelect (uint8 u8ADC_ClockDivider)
{
    ADCCFG_ADIV = u8ADC_ClockDivider;
}

void vfnADC_SetSampleTime (uint8 u8ADC_SampleTime)
{
    ADCCFG_ADLSMP = u8ADC_SampleTime;    
}

void vfnADC_ChannelSelect(uint8 u8channel) 
{
	ADCSC1_ADCH = (u8channel & 0x1F);
}

uint16 u16ADC_GetResult (void)
{	
    return (ADCR & 0x03FF);
}

void vfnADC_UseBusClock (void)
{
    ADCCFG_ADICLK = 0;
}

void vfnADC_PinEnable(uint8 u8pin) 
{
    if(u8pin > 15)  // If selected pin is out of range, return   
        return;
    else if (u8pin > 7)
    {
        u8pin -= 8;
        APCTL2 |= (1<<u8pin);
    } 
    else
    {
        APCTL1 |= (1<<u8pin);
    }  
}

void vfnADC_PinDisable(uint8 u8pin) 
{
    if(u8pin > 15)  // If selected pin is out of range, return   
        return;
    else if (u8pin > 7)
    {
        u8pin -= 8;
        APCTL2 &= ~(1<<u8pin);
    } 
    else
    {
        APCTL1 &= ~(1<<u8pin);
    }
}
          
uint8 u8ADC_CCFCheck (void) 
{
    return ADCSC1_COCO;
}

void vfnADC_EnableInterrupt (void) 
{
    ADCSC1_AIEN = 1;     
}

void vfnADC_DisableInterrupt (void) 
{
    ADCSC1_AIEN = 0;   
}

void vfnADC_ContConv (void) 
{
    ADCSC1_ADCO = 1;  
}

void vfnADC_SingleConv (void) 
{
    ADCSC1_ADCO = 0;  
}

